home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-03-04 | 3.5 KB | 126 lines | [TEXT/ToyS] |
- property sasDoFolders : true
- property sasOutExtension : ".cat" -- Added to file name of first file for output file (can't be empty string)
- property sasFoldExtension : " ƒ" -- Added to folder name when folder is concated (can be empty string)
-
- property sasFilesProgLoc : {0, 0}
-
-
- on open fsObjs
- set fileList to {}
-
- repeat with fsObj in fsObjs
- set fInfo to basic info for fsObj
-
- if (catalog kind of fInfo) is a folder then
- if (sasDoFolders) then
- ConcatFolder(fsObj)
- else
- beep
- end if
- else
- set fileList to fileList & fsObj
- end if
- end repeat
-
- if (count (fileList)) > 1 then ¬
- |concat|(fileList, item 1 of fileList)
- end open
-
-
-
- on ConcatFolder(fsObj)
- set catFold to (fsObj as string)
- set fileList to {}
-
- set fileNames to list folder fsObj
-
- repeat with fname in fileNames
- (* Only add files; ignore deeper levels
- If you want to concat deeper folders into separate files, then just ConcatFolder(newItem)
- If you want to concat them to the main file, you'll need to do a bit more…
- *)
- set newItem to (catFold & fname) as alias
- if (catalog kind of (basic info for newItem) is a file) then ¬
- set fileList to fileList & {newItem}
- end repeat
-
- if (count (fileList)) > 1 then ¬
- |concat|(fileList, fsObj)
- end ConcatFolder
-
-
- on |concat|(fsObjs, fsFirstSrc)
- set idx to 0
- set cnt to the number of items in fsObjs
-
- -- File Progress Window
- set pgFiles to display progress titled "Concatenating" subtitled ¬
- "Setting up…" maximum cnt located at sasFilesProgLoc
-
- -- Open new file based on first source file/folder
- set fsInfo to extended info for fsFirstSrc
-
- if (the catalog kind of fsInfo is a file) then
- -- Create output in same folder as file
- set outRef to open fork from fsFirstSrc ¬
- extended by sasOutExtension with write access
- else
- -- Create output of same type as first file we use…
- set fsItemInfo to basic info for (item 1 of fsObjs)
- set firstType to system type of fsItemInfo
- set firstCreator to system creator of fsItemInfo
-
- -- Create output at same level as folder (in its parent)
- set outRef to open fork from (parent spec of fsInfo) ¬
- named (catalog name of fsInfo) & sasFoldExtension & sasOutExtension ¬
- of type firstType of creator firstCreator ¬
- with write access
- end if
-
- -- Concat the files
- repeat with fsObj in fsObjs
- set fInfo to basic info for fsObj
- set fLen to data fork length of fInfo
-
- if (fLen is not 0) then
- set fsName to catalog name of fInfo
-
- display progress pgFiles subtitled fsName
- set oneRef to open fork from fsObj
-
- set pgOne to display progress titled fsName maximum fLen
- set maxLen to fLen
-
- repeat while (fLen > 0)
- -- Do a 64K chunk (or whatever is left)
- set bufLen to 64 * 1024
- if (bufLen > fLen) then set bufLen to fLen
- set fLen to fLen - bufLen
-
- -- Read a chunk
- display progress pgOne labeled "Reading…"
- set buf to read data from oneRef using buffer size bufLen
-
- -- Write the chunk
- display progress pgOne labeled "Writing…" value (maxLen - fLen) with alternate color
- write data to outRef given «class Data»:buf
-
- display progress pgOne value (maxLen - fLen) without alternate color
- end repeat
-
- display progress pgOne with disposal
- close fork oneRef
- end if
-
- -- Save location of progress window
- set idx to idx + 1
- set sasFilesProgLoc to screen location of (display progress pgFiles value idx)
- end repeat
-
- -- Close file
- close fork outRef
-
- -- Kill progress window
- display progress pgFiles with disposal
- end |concat|
-